package com.swak.rpc.config.model;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import org.springframework.util.Assert;

import com.swak.rpc.config.ReferenceConfig;
import com.swak.utils.StringUtils;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * ConsumerModel.
 * 
 * @author lifeng
 */
@Getter
@Setter
@Accessors(chain = true)
public class ConsumerModel {
	private String serviceKey;
	private final ServiceDescriptor serviceModel;
	private final ReferenceConfig<?> referenceConfig;
	private final Set<String> apps = new TreeSet<>();
	private Object proxyObject;
	private Map<String, AsyncMethodInfo> methodConfigs = new HashMap<>();
	private ServiceMetadata serviceMetadata;
	private Map<Method, MethodDescriptor> methodModels = new HashMap<>();

	public ConsumerModel(String serviceKey, Object proxyObject, ServiceDescriptor serviceModel,
			ReferenceConfig<?> referenceConfig) {
		Assert.isTrue(StringUtils.isNotEmpty(serviceKey), "Service name can't be null or blank");
		this.serviceKey = serviceKey;
		this.proxyObject = proxyObject;
		this.serviceModel = serviceModel;
		this.referenceConfig = referenceConfig;
	}
}
